import {base_url} from "../../config/config.js"
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    job:{},
    merchant:{}
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let job_id = options.job_id
    let merchantid = options.merchantid
    let that = this;
    wx.request({
      url: base_url + "/job?id=" + job_id,
      method: "GET",
      success(res) {
        console.log(res)
        if (res.statusCode == 200){
          that.setData({
            "job":res.data.job
          })
        } else {
          wx.showToast({
            title: '获取数据失败！',
            icon: "none"
          })
        }
      },
      fail(res) {
        wx.showToast({
          title: '获取数据失败！',
          icon: "none"
        })
      }
    });

    wx.request({
      url: base_url + "//merchant?id=" + merchantid,
      method: "GET",
      success(res) {
        console.log(res)
        if (res.statusCode == 200) {
          that.setData({
            "merchant": res.data.data
          })
        } else {
          wx.showToast({
            title: '获取数据失败！',
            icon: "none"
          })
        }
      },
      fail(res) {
        wx.showToast({
          title: '获取数据失败！',
          icon: "none"
        })
      }
    })
  },
  get_job(){
    let that = this;
    wx.request({
      url: base_url + "/stu/work",
      method: "POST",
      data:{
        "stuid": app.globalData.user_id,
        "detailid": that.data.job.id
      },
      success(res) {
        if(res.statusCode == 200){
          wx.showToast({
            title: res.data.msg,
            icon: "none"
          })
        } else {
          wx.showToast({
            title: '操作失败！',
            icon: "none"
          })
        }
      },
      fail(res) {
        wx.showToast({
          title: '操作失败！',
          icon: "none"
        })
      }
    })
  }
})